package com.ha.springcloud.controller;


import com.ha.springcloud.pojo.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@Controller
public class LoginCotroller {

    @Autowired
    private RestTemplate restTemplate;

    private static final String REST_URL_PREFIX="http://PROVIDER-EMPLOYEE";

    @RequestMapping("/user/login")
    public String login(@RequestParam("Id") String id, @RequestParam("password") String password, Model model){

        Employee employee=restTemplate.getForObject(REST_URL_PREFIX+"/emp/get/"+id, Employee.class);
        System.out.println(employee);
        if (employee==null)
        {
            model.addAttribute("msg","用户不存在");
            return "index";
        }
        if(employee.getPassword().equals(password)){
            return "dashboard";
        }else {
            model.addAttribute("msg","用户名或者密码错误");
            return "index";
        }



    }

}
